#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
@File    :   mail.py
@Time    :   2024-08-01 13:29:41
@Author  :   chakcy 
@Email   :   947105045@qq.com
@description   :   邮箱相关接口
'''

from fastapi import APIRouter, Security, WebSocket, Depends

from ..dependencies.jwt import Authorization
from ..dependencies.celery import app as celery_app
from ..models import CommonResponseModel
from ..dependencies.redis import RedisDependency
from ..service import MailService


router = APIRouter(prefix="/mail", tags=["mail-controller"])

# @router.post('/send_mail', response_model=CommonResponseModel)
# def send_mail(mail: str, token: str = Security(Authorization)):
#     result = celery_app.send_task('send_mail', kwargs={"mail": mail})
#     return CommonResponseModel(data={"result": result.get()}, code=200, message="邮件发送成功").model_dump()


@router.websocket("/ws/mail")
async def mail_ws(websocket: WebSocket, 
                  redis: RedisDependency = Depends(RedisDependency)):
    await MailService.send_mail(websocket=websocket, redis=redis)